<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of View_stock
 *
 * @author admin
 */
class view_stock extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('stock_model');
    }

    public function index() {
        $id = $this->input->get('id');
        $stock = $this->stock_model->get_stock_by_id($id);
        $this->_set_form($stock);
        $this->load->view('stock/view_stock', $this->data);
    }

    private function _set_form($stock) {
        $utility = new Config_utility();
        $this->data['lbl_code'] = '<h5>' . $utility->check_str($stock[0]->stock_code) . '</h5>';
        $this->data['lbl_name'] = '<h5>' . $utility->check_str($stock[0]->stock_name) . '</h5>';
        $this->data['lbl_main_type'] = '<h5>' . $utility->check_str($stock[0]->main_type_name) . '</h5>';
        $this->data['lbl_sub_type'] = '<h5>' . $utility->check_str($stock[0]->sub_type_name) . '</h5>';
        $this->data['lbl_brand'] = '<h5>' . $utility->check_str($stock[0]->brand_name) . '</h5>';
        $this->data['lbl_qty'] = '<h5>' . $utility->check_str($utility->format_number($stock[0]->stock_qty).' '.$stock[0]->classifire) . '</h5>';
        $this->data['lbl_price'] = '<h5>' . $utility->check_str($utility->format_number($stock[0]->stock_price)).'&nbsp;&nbsp;บาท' . '</h5>';
        $this->data['lbl_alert_below'] = '<h5>' . $utility->check_str($utility->format_number($stock[0]->alert_below)).'&nbsp;&nbsp;ชิ้น' . '</h5>';
        $this->data['lbl_detail'] = '<h5>' . $utility->check_str($stock[0]->stock_detail) . '</h5>';

        $img = $this->stock_model->get_stock_img_by_id($stock[0]->stock_id);
        if ($img != NULL) {
            $this->data['img_picture'] = '<img src="' . base_url() . 'uploads/stocks/' . $img[0]->file_name . '" style="width:355px" \>';
        } else {
            $this->data['img_picture'] = '<img src="' . base_url() . 'images/driver/no_image.jpg" style="width:355px"  \>';
        }
    }

}
